package com.qqtop10.manager.controller.autotask;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.qqtop10.manager.model.Order;
import com.qqtop10.manager.service.OrderService;

@Component
public class AutomaticReceiving {

	@Autowired
	@Qualifier("orderService")
	private OrderService orderService;

	@Scheduled(cron = "0 0/1 * * * ? ")
	public void runReceiving() {
		List<Order> list = orderService.selectAllUnReceiveOrder();
		for (Order order : list) {
			Date orderDate = order.getCreatetime();
			long orderTime = orderDate.getTime();
			long nowTime = System.currentTimeMillis();
			// 15天前
			long beforeTime = nowTime - (1000 * 60 * 60 * 24 * 15);
			// 如果15天前的时间戳还大于订单的创建时间戳，则认为已经超过了15天了。
			if (beforeTime > orderTime) {
				order.setStatus(4);
				orderService.updateByUuid(order);
			}
		}
	}

}
